package com.xxd.dfs.client;

/**
 * @author: XiaoDong.Xie
 * @create: 2020-08-18 10:14
 * @description: 分布式文件系统的客户端
 */
public class DFSClient {
    /**
     * 文件操作接口
     */
    private FileSystem fileSystem;

    public DFSClient(String ip, int port) {
        NameNodeClient namenode = new NameNodeClient(ip, port);
        this.fileSystem = new FileSystemImpl(namenode);
    }

    /**
     * 创建目录
     *
     * @param path 绝对路劲
     * @return
     */
    public boolean mkdir(String path) {
        System.out.println("正在创建路劲为 path = " + path);
        return fileSystem.mkdir(path);
    }

    /**
     * 关闭namenode
     */
    public void shutdown() {
        System.out.println("正在关闭namenode....");
        try {
            fileSystem.shutdown();
        } catch (Exception e) {

        }
    }

    /**
     * 创建文件
     */
    public void upload(String fileName) {
        FileInfo fileInfo = new FileInfo();
        fileInfo.setFileName("/test/aaa.jpg");
        fileInfo.setFileLength(5000);

        fileSystem.upload(fileInfo);
    }
}
